/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.jiadakeji.ppm.modules.business.service;

import com.jiadakeji.ppm.common.persistence.Page;
import com.jiadakeji.ppm.common.service.CrudService;
import com.jiadakeji.ppm.common.utils.IdGen;
import com.jiadakeji.ppm.common.utils.StringUtils;
import com.jiadakeji.ppm.modules.business.dao.CustomerDao;
import com.jiadakeji.ppm.modules.business.entity.Customer;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 小区住户Service
 * @author HHAOYU
 * @version 2019-07-09
 */
@Service
@Transactional(readOnly = true)
public class CustomerService extends CrudService<CustomerDao, Customer> {

	public Customer get(String id) {
		return super.get(id);
	}
	
	public List<Customer> findList(Customer customer) {
		return super.findList(customer);
	}
	
	public Page<Customer> findPage(Page<Customer> page, Customer customer) {
		return super.findPage(page, customer);
	}
	
	@Transactional(readOnly = false)
	public void save(Customer customer) {
		if(StringUtils.isBlank(customer.getNumCode())) {
			for (int i = 0; i < 100; i++) {
				customer.setNumCode(IdGen.generaChar(9));
				Customer c = dao.getByNumCode(customer);
				if (null == c) {
					break;
				}
			}
		}
		super.save(customer);
	}


	@Transactional(readOnly = false)
	public void delete(Customer customer) {
		//TODO 删除其它关联表
		
		super.delete(customer);
	}

}